/*
 * @Author: cqg
 * @Date: 2020-11-10 23:18:06
 * @LastEditors: cqg
 * @LastEditTime: 2020-11-22 23:10:40
 * @Description: file content
 */
import { searchDisposedList } from "@/views/wy-asset-management/disposed/api/disposed.js";
import { getDict } from "~/utils";
export default {
    name: "resource-manage",
    provide () {
        return {
            initList: this.query
        };
    },

    data () {
        return {
            loading: true,
            //表单数据
            tableData: [],
            // 分页
            pager: {
                total: 0, // 总页数
                current: 1, // 当前页数
                size: 20 // 每页显示多少条
            },
            // 请求参数
            params: {
                current: 1,
                size: 20,
                keyword: ""
            },
            //过滤条件
            filterList: [
                {
                    label: "资产分类",
                    inputType: "dict",
                    dictName: "asset-classification",
                    name: "assetClassificationList"
                },
                {
                    label: "使用状况",
                    inputType: "dict",
                    dictName: "asset-use-status",
                    name: "useStatusList"
                }
            ]
        };
    },
    //载入事件
    mounted () {
        //查询
        this.query();
    },

    methods: {
        /**
         * 查询方法
         * @param param
         */
        query (params = {}) {
            this.loading = true;
            let req = { ...this.params, ...params };
            !req.assetClassificationList && delete req.assetClassificationList;
            !req.useStatusList && delete req.useStatusList;
            searchDisposedList(req)
                .then(res => {
                    const { current, size, total, records } = res.data.data;
                    this.tableData = records;
                    this.params = req;
                    this.pager = { total, current, size };
                    this.loading = false;
                })
                .catch(error => {
                    this.$message({
                        type: "error",
                        message: "查询失败"
                    });
                })
                .finally(() => (this.loading = false));
        },
        /**
         * 码值转换
         * @param row
         * @param column
         * @param cellValue
         * @returns {string|*}
         */
        dictVal_assetClassification (row, column, cellValue) {
            let obj = getDict("asset-classification").find(
                p => p.value == cellValue
            );
            if (obj) {
                return obj.label;
            }
            return "";
        },

        /**
         * 码值转换
         * @param row
         * @param column
         * @param cellValue
         * @returns {string|*}
         */
        dictVal_useStatusList (row, column, cellValue) {
            let obj = getDict("asset-use-status").find(
                p => p.value == cellValue
            );
            if (obj) {
                return obj.label;
            }
            return "";
        }
    }
};
